package fch;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import robocode.Rules;

/**
 * Test that the CrazyTracker's calculatePower method returns the expected values.
 * @author Christopher Foo
 *
 */
public class TestCalculatePower {

  /**
   * Test that the CrazyTracker's calculatePower method returns the expected values.
   */
  @Test
  public void test() {
    CrazyTracker robot = new CrazyTracker();
    
    //Test out of range
    assertEquals("Out of range, high hit rate", -1, robot.calculatePower(500, 5, 5), 0.01);
    
    assertEquals("Out of range, low hit rate", -1, robot.calculatePower(400, 0, 5), 0.01);
    
    //Test long range
    assertEquals("Long range, high hit rate", Rules.MAX_BULLET_POWER / 3, 
                  robot.calculatePower(499, 5, 5), 0.01);
    
    assertEquals("Long range, high hit rate (lower boundary)", Rules.MAX_BULLET_POWER / 3, 
        robot.calculatePower(300, 5, 5), 0.01);
    
    assertEquals("Long range, low hit rate", Rules.MAX_BULLET_POWER / 3, 
                  robot.calculatePower(399, 0, 5), 0.01);
    
    assertEquals("Long range, low hit rate (lower boundary)", Rules.MAX_BULLET_POWER / 3, 
        robot.calculatePower(300, 0, 5), 0.01);
    
    //Test medium range
    assertEquals("Medium range, high hit rate", (Rules.MAX_BULLET_POWER * 2) / 3, 
        robot.calculatePower(299, 5, 5), 0.01);
    
    assertEquals("Medium range, high hit rate (lower boundary)", (Rules.MAX_BULLET_POWER * 2) / 3, 
        robot.calculatePower(200, 5, 5), 0.01);
    
    assertEquals("Medium range, low hit rate", (Rules.MAX_BULLET_POWER * 2) / 3, 
        robot.calculatePower(299, 0, 5), 0.01);
    
    assertEquals("Medium range, low hit rate (lower boundary)", (Rules.MAX_BULLET_POWER * 2) / 3, 
        robot.calculatePower(200, 0, 5), 0.01);
    
    //Test short range
    assertEquals("Short range, high hit rate", Rules.MAX_BULLET_POWER, 
        robot.calculatePower(199, 5, 5), 0.01);
    
    assertEquals("Short range, high hit rate (lower boundary)", Rules.MAX_BULLET_POWER, 
        robot.calculatePower(0, 5, 5), 0.01);
    
    assertEquals("Short range, low hit rate", Rules.MAX_BULLET_POWER, 
        robot.calculatePower(99, 0, 5), 0.01);
    
    assertEquals("Short range, low hit rate (lower boundary)", Rules.MAX_BULLET_POWER, 
        robot.calculatePower(0, 0, 5), 0.01);
  }

}
